how to create k8s cluster with kubeadm on centos7

  1. install dependencies

    swapoff -a
    yum install socat conntrack yum-utils nfs-utils chrony -y
    yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
    mkdir -p /etc/docker
    cat <<EOF |  tee /etc/docker/daemon.json
    {
      "exec-opts": ["native.cgroupdriver=systemd"],
      "log-driver": "json-file",
      "log-opts": {
        "max-size": "100m"
      },
      "storage-driver": "overlay2"
    }
    EOF
    cat <<EOF |  tee /etc/modules-load.d/k8s.conf
    br_netfilter
    EOF
    cat <<EOF |  tee /etc/sysctl.d/k8s.conf
    net.bridge.bridge-nf-call-ip6tables = 1
    net.bridge.bridge-nf-call-iptables = 1
    EOF
    sysctl --system
    cat <<EOF |  tee /etc/yum.repos.d/kubernetes.repo
    [kubernetes]
    name=Kubernetes
    baseurl=https://packages.cloud.google.com/yum/repos/kubernetes-el7-\$basearch
    enabled=1
    gpgcheck=1
    repo_gpgcheck=1
    gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg
    exclude=kubelet kubeadm kubectl
    EOF
    yum install docker-ce -y
    systemctl start docker && systemctl enable docker
    yum install -y kubelet-1.23.17 kubectl-1.23.17 kubeadm-1.23.17 --disableexcludes=kubernetes
    systemctl enable --now kubelet && systemctl disable firewalld && systemctl stop firewalld
    #remember to append to hosts file
    kubeadm init --apiserver-advertise-address=192.168.0.1 --control-plane-endpoint 192.168.0.1 --pod-network-cidr=172.16.0.0/16
    #kubectl taint nodes --all node-role.kubernetes.io/master-
    curl -LO https://docs.projectcalico.org/manifests/tigera-operator.yaml
    curl -LO https://docs.projectcalico.org/manifests/custom-resources.yaml
    

    edit yaml, replace operator version(1.17.4) and address, apply yaml.

  2. add nodes

    kubeadm token create --print-join-command
    

references: